package com.lecture.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


import com.lecture.hibernate.pojo.UserDAO;


import com.lecture.hibernate.pojo.User;
import com.lecture.service.UserService;
public class UserServiceImpl implements UserService {

	private Log logger = LogFactory.getLog(this.getClass());
	
	//the smtp server host address
	private String smtpHost;
	
	//the default sender email address
	private String defaultSenderAddress;
	
	//the default sender name
	private String defaultSenderName;
	
	//the receiver email addresses
	private List receiverAddresses;
	
	//the UserDao used
	private UserDAO userDao;
	public UserDAO getUserDAO()
	{
		return this.userDao;
	}
	public void setUserDAO(UserDAO dao)
	{
		this.userDao = dao;
	}
	public void setSmtpHost(String host) {
		this.smtpHost = host;
	}
	
	public void setDefaultSenderAddress(String newDefaultSenderAddress) {
		this.defaultSenderAddress = newDefaultSenderAddress;
	}
	
	public void setDefaultSenderName(String newDefaultSenderName) {
		this.defaultSenderName = newDefaultSenderName;
	}
	
	public void setReceiverAddresses(List newDefaultReceiverAddresses) {
		this.receiverAddresses = newDefaultReceiverAddresses;
	}
	
	public void setUserDao(UserDAO newUserDao) {
		this.userDao = newUserDao;
	}
	
	/**
	 * @see UserService#login(String, String)
	 */
	public User login(long id, String password) throws Exception {
		try {
			User user = this.userDao.findById(id);
			
			if (user != null) {
				if (!user.getPass().equals(password)) {
					user = null;
				}
			}
			return user;
		}		 catch (Exception e) {
			this.logger.error("Could not login", e);
			return null;
		}
	}
	

}
